﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;

namespace IronCow.Posh.Commands
{
    public class RtmTaskCmdlet : RtmCmdlet
    {
        [Parameter(
            Mandatory = true,
            ParameterSetName = "TaskId",
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "The ID of the task to process.")]
        [Alias("Id")]
        public string TaskId { get; set; }

        [Parameter(
            Mandatory = true,
            ParameterSetName = "TaskId",
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "The ID of the task series to process.")]
        public string SeriesId { get; set; }

        [Parameter(
            Mandatory = true,
            ParameterSetName = "TaskId",
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "The ID of the task list to process.")]
        public string ListId { get; set; }

        [Parameter(
            Position = 1,
            Mandatory = true,
            ParameterSetName = "InputObject",
            ValueFromPipeline = true,
            HelpMessage = "The task to process.")]
        [ValidateNotNull]
        public Task InputObject { get; set; }

        protected RtmTaskCmdlet()
        {
            TaskId = null;
            SeriesId = null;
            ListId = null;
        }

        protected Task GetTaskRecord()
        {
            switch (ParameterSetName)
            {
                case "TaskId":
                    return GetTaskRecordById();
                case "InputObject":
                    return GetTaskRecordByInputObject();
                default:
                    return null;
            }
        }

        private Task GetTaskRecordByInputObject()
        {
            return InputObject;
        }

        protected Task GetTaskRecordById()
        {
            TaskList taskList = Rtm.TaskLists.GetById(ListId, true);
            Task task = taskList.Tasks.GetById(SeriesId, TaskId, true);
            return task;
        }
    }
}
